Fly3D SDK

Tutorials

Home

Tutorial 10

Adding a new object to a Fly3D plug-in

· Introduction

After finishing this tutorial you will have added a new object to an existing Fly3D plug-in. The object we will add is a simple object that has a mesh representation and moves around bouncing on walls as a sphere.

· Visual C++ operations

1) Open the plug-in project created in last tutorial.

2) Add a new type to the enumeration on the beginning of tutorial.h:

enum
{
   TYPE_BLINK_LIGHT=100000,
   TYPE_BOUNCE_MESH,
}

3) Add the following lines to the end of the tutorial.h file:

class bounce_mesh : public bsp_object
{
public:
  bounce_mesh() { type=TYPE_BOUNCE_MESH; };

  // the obejct's mesh
  mesh *objmesh;

  // no step() is defined, using the particle base class step()

  // this will handle drawing and collision with the object
  mesh *get_mesh() { return objmesh; };

  int get_custom_param_desc(int i,param_desc *pd);
  bsp_object *clone();
};

class bounce_mesh_desc : public class_desc
{
public:
  void *create() { return new bounce_mesh; };
  char *get_name() { return "bounce_mesh"; };
  int get_type() { return TYPE_BOUNCE_MESH; };
};

4) Add the following global variable to the beginning of the tutorial.cpp file:

bounce_mesh_desc cd_bounce_mesh;

5) The exported num_classes() function in the tutorial.cpp file should look like this as we now have two classes:

__declspec( dllexport )
int num_classes()
{
   return 2;
}

6) The exported get_class_desc() function in the tutorial.cpp file should look like this as we now have two classes:

__declspec( dllexport )
class_desc *get_class_desc(int i)
{
  switch(i)
  {
    case 0:
      return &cd_blink_light;
    case 1:
      return &cd_bounce_mesh;
    default: return 0;
  }
}

7) Add the following lines to the end of the tutorial.cpp file:

bsp_object *bounce_mesh::clone()
{
  bounce_mesh *tmp=new bounce_mesh;
  *tmp=*this;
  tmp->source=this;
  return tmp;
}

int bounce_mesh::get_custom_param_desc(int i,param_desc *pd)
{
  if (pd!=0)
    switch(i)
    {
      case 0:
        pd->type='3';
        pd->data=&objmesh;
        strcpy(pd->name,"objmesh");
        break;
    }
  return 1;
}

· flyEditor operations

1) Open the level .fly file cretated in previous tutorials in flyEditor.

2) Add a new bounce_mesh object and set its parameters as follows:

vel      = 0.1 0.1 0.1 (diagonal velocity)
mass     = 1.0 (object mass)
bump     = 1.0 (bumping factor)
friction = 1.0 (friction factor)
radius   = 10 (the object collision radius)
colflag  = 1 (turns collision detection on)
active   = 1 (activate on startup)
life     = 30000 (bounce for 30 seconds and die)
objmesh  = select any 3ds file to be used as the object's mesh

3) Run the level (setting the render and starting simmulation).

4) With the bouce_mesh object selected, click the activate button on the toolbar to add a new instance of the object to the simmulation. You should see the bounce_mesh moving and colliding with the level walls.